CygNet Studio > Using TheFrame/TheView > Adding Context Menus > Standard Context Menus

Standard Context Menus

Standard context menu items can be configured to appear on the right-click context menu on just TheView itself or of any object on the TheView. For a detailed example of configuring a Standard Context Menu, see Standard Context Menu Example below.

TheView

TheView has a [ContextMenuView] property that can be configured in design time. Context menu items added here are visible only when the user right-clicks on the TheView, not on an object. These items are appended to the standard context menu.

View Configuration

One of the options on the right-click menu on the TheView is Configuration, which displays the View Configuration dialog box. From this dialog box you have Facility Template information, and can set Units, Update Interval, and view File Properties (File Path and File Serialization Version).

View Configuration

CygNet Studio Objects

TheView also has a [ContextMenuObjects] property that sets the default items for context menus opened on objects, not on TheView itself. These commands can be added to and overridden for individual objects using their [ContextMenu] properties.

Each context menu item is configured with an Event ID, which must be unique within a context menu. When a context menu item is clicked, an event handler on TheView (EventContextMenuView or EventContextMenuObjects) or on individual objects (EventContextMenu) can perform an action based on the Event ID and the calling object.

Standard Context Menu Example

The following example creates a small screen using a Slider object to set a "scale factor," which could be used in graphical applications or to otherwise scale data sets. A context menu item, "Reset" is used on the value a Text tool to reset the value to the default scale factor. A context menu item on TheView toggles the visibility of the scale controls.

To Configure a Context Menu

  1. Create a new Studio screen.
  2. Add a Slider and a Text control to TheView. Name the Slider control "sldScaleFactor" and the Text control "txtScaleFactor" in the (ObjectCode) property of each tool.
  3. In the Slider control’s properties, set MinimumEq to 0.1 and MaximumEq to 0.8.
  4. In the Text control’s properties, set [DisplayItem] to Text.
  5. Add a menu item to the Text control.
  1. In the Text control’s properties, click [ContextMenu]. This opens the Context Menu Configuration dialog box.
  2. Click Add to add a new menu item.
  3. For the new menu item, set the Item Text to "Reset" and the Event ID to RESET.
  4. Click OK.
  1. Add a menu item to TheView.
  1. In TheView’s properties, click [ContextMenuView]. This opens the Context Menu Configuration dialog box.
  2. Click Add to add a new menu item.
  3. For the new menu item, set the Item Text to "Toggle Scale Visibility" and the Event ID to TOGGLESCALEVISIBILITY.
  4. Click OK.
  1. Add the following script to the general declarations section.
  1. Open the Script Editor and navigate to (General), (Declarations).
  2. Enter the following script to set a default scale factor.

'(Declarations)

 

Dim defaultScaleFactor

defaultScaleFactor = 0.1

 

'End of (Declarations)

  1. Add script to initialize the Slider and Text controls.
  1. In the script editor, enter the following script in the Text control’s EventInitialize event.

Sub txtScaleFactor_EventInitialize()

Dim This : Set This = txtScaleFactor

This.Text = defaultScaleFactor

End Sub

  1. In the script editor, enter the following script in the Slider control’s EventInitialize event.

Sub SldScaleFactor_EventInitialize()

Dim This : Set This = SldScaleFactor

This.Value = defaultScaleFactor

End Sub

  1. Add script to synchronize the Slider with the Text control.
  1. In the script editor, navigate to the Slider control’s EventInitialize event.
  2. Enter the following script.

Sub SldScaleFactor_EventChange()

Dim This : Set This = SldScaleFactor

txtScaleFactor.Text = This.Value

End Sub

  1. Add script to handle the Reset command on the Text control’s context menu.
  1. In the script editor, navigate to the Slider control’s EventInitialize event.
  2. Enter the following script. Note that checking for the EventID value is not necessary because only one menu item exists. However, this would be necessary for multiple menu items.

Sub txtScaleFactor_EventContextMenu(EventID)

Dim This : Set This = txtScaleFactor

If EventID = "RESET" Then

This.Text = defaultScaleFactor

SldScaleFactor.Value = defaultScaleFactor

End If

End Sub

  1. Add script to handle the visibility toggle command on the View’s context menu.
  1. In the script editor, navigate to the View’s EventInitialize event.
  2. Enter the following script. Note that checking for the EventID value is not necessary because only one menu item exists. However, this would be necessary for multiple menu items.

Sub TheView_EventContextMenuView(EventID)

Dim This : Set This = TheView

If EventID = "TOGGLESCALEVISIBILITY" Then

If txtScaleFactor.Visible = 1 Then 'True

txtScaleFactor.Visible = False

SldScaleFactor.Visible = False

Else

txtScaleFactor.Visible = True

SldScaleFactor.Visible = True

End If

End If

End Sub

  1. Save the screen and switch to Run mode. Try changing the Slider value, then right-click the Text control and click Reset on the Context menu. Then try right-clicking View to use the Toggle Scale Visibility menu item.
Back to top

Let us know how we can improve this topic.

CygNet at weatherford.com

© 2020 Weatherford. All rights reserved.